package main;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.*;

public class IntroState extends BasicGameState {

	//variables and shit
	public static final int ID = 1;
	Image Cooper;
	Color fade = new Color(Color.white);
	long start;
	
	@Override
	public int getID() {
		return ID;
	}


	@Override
	public void init(GameContainer gc, StateBasedGame sbg)
			throws SlickException {
		// TODO Auto-generated method stub
		Cooper = new Image("/res/Untitled-3.png");
		start = gc.getTime();
		fade.a = 0;
	}


	@Override
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
			throws SlickException {
		// TODO Auto-generated method stub
		g.setColor(Color.pink);
		g.fillRect(0, 0, gc.getWidth(), gc.getHeight());
		// the fade in logo
		Cooper.setColor(0, fade.r, fade.g, fade.b, fade.a);
		Cooper.setColor(1, fade.r, fade.g, fade.b, fade.a);
		Cooper.setColor(2, fade.r, fade.g, fade.b, fade.a);
		Cooper.setColor(3, fade.r, fade.g, fade.b, fade.a);
		Cooper.draw(gc.getWidth() / 2 - Cooper.getWidth() / 2, gc.getHeight() / 2 - Cooper.getHeight() / 2);
		
		//g.drawImage(Cooper, gc.getWidth() / 2 - Cooper.getWidth() / 2, gc.getHeight() / 2 - Cooper.getHeight() / 2);
	}


	@Override
	public void update(GameContainer gc, StateBasedGame sbg, int delta)
			throws SlickException {
		// TODO Auto-generated method stub
		colorAlgorithm(fade, 1.0f, 0.01f);
		if (start+2000 <= gc.getTime()) {
			sbg.enterState(MainMenuState.ID, new FadeOutTransition(Color.black, 500), new FadeInTransition());
		}
	}


	private void colorAlgorithm(Color colorfade, float target, float speed) {
		// TODO Auto-generated method stub
		colorfade.a += (target - colorfade.a) * speed;
	}

	
}
